// 全面验证PatientDetail.ets文件语法结构和接口声明
console.log('=== 全面验证PatientDetail.ets文件语法结构 ===\n');

const fs = require('fs');
const path = require('path');

const patientDetailPath = path.join(__dirname, 'entry', 'src', 'main', 'ets', 'features', 'doctor', 'PatientDetail.ets');

if (fs.existsSync(patientDetailPath)) {
  console.log('✓ PatientDetail.ets 文件存在');
  
  const content = fs.readFileSync(patientDetailPath, 'utf8');
  
  // 1. 检查接口声明位置
  const hasRouterParamsInterface = content.includes('interface RouterParams');
  const routerParamsLineNumber = content.indexOf('interface RouterParams');
  const componentStartLineNumber = content.indexOf('@Entry');
  const routerParamsOutsideComponent = routerParamsLineNumber < componentStartLineNumber;
  
  // 2. 检查语法结构
  const hasStructDeclaration = content.includes('struct PatientDetail');
  const hasBuildMethod = content.includes('build()');
  const hasAboutToAppear = content.includes('aboutToAppear()');
  
  // 3. 检查类型安全
  const noUnknownType = !content.includes('unknown');
  const noInOperator = !content.includes("'patientId' in params");
  const usesTypeOfCheck = content.includes('typeof patientId ===');
  
  // 4. 检查方法定义
  const hasGoBack = content.includes('goBack()');
  const hasUpdatePatientData = content.includes('updatePatientData(patientId: string)');
  
  // 显示检查结果
  console.log('\n✓ 接口声明检查:');
  console.log(`  - 定义了RouterParams接口: ${hasRouterParamsInterface ? '✓' : '✗'}`);
  console.log(`  - 接口在组件外部: ${routerParamsOutsideComponent ? '✓' : '✗'}`);
  
  console.log('\n✓ 语法结构检查:');
  console.log(`  - 结构体声明正确: ${hasStructDeclaration ? '✓' : '✗'}`);
  console.log(`  - 包含build方法: ${hasBuildMethod ? '✓' : '✗'}`);
  console.log(`  - 包含aboutToAppear生命周期方法: ${hasAboutToAppear ? '✓' : '✗'}`);
  
  console.log('\n✓ 类型安全检查:');
  console.log(`  - 没有使用unknown类型: ${noUnknownType ? '✓' : '✗'}`);
  console.log(`  - 没有使用in操作符: ${noInOperator ? '✓' : '✗'}`);
  console.log(`  - 使用typeof进行类型检查: ${usesTypeOfCheck ? '✓' : '✗'}`);
  
  console.log('\n✓ 方法定义检查:');
  console.log(`  - 包含goBack方法: ${hasGoBack ? '✓' : '✗'}`);
  console.log(`  - 包含updatePatientData方法: ${hasUpdatePatientData ? '✓' : '✗'}`);
  
  // 所有检查是否通过
  const allChecksPass = hasRouterParamsInterface && 
                        routerParamsOutsideComponent && 
                        hasStructDeclaration && 
                        hasBuildMethod && 
                        hasAboutToAppear && 
                        noUnknownType && 
                        noInOperator && 
                        usesTypeOfCheck && 
                        hasGoBack && 
                        hasUpdatePatientData;
  
  // 总结
  console.log('\n=== 验证总结 ===');
  if (allChecksPass) {
    console.log('✓ 所有语法和结构检查通过!');
    console.log('1. RouterParams接口已正确放置在组件外部');
    console.log('2. 移除了所有不支持的语法特性');
    console.log('3. 保留了必要的类型安全检查');
    console.log('4. 所有方法定义正确');
    console.log('\nPatientDetail.ets文件现在应该能够正确编译');
  } else {
    console.error('✗ 部分检查未通过，请检查上面的结果');
  }
} else {
  console.error('✗ 找不到 PatientDetail.ets 文件');
}